/**
 * Created by Administrator on 2017/9/20.
 */
define(['jquery','knockout'],function($){
    var selectChange = function (self) {
        console.log(self.selectedIdentity());
        console.log(self.username());
        console.log(self.password());
    };

    var submitLoginInfo = function (self,root) {
        $.ajax({
            url: '/userLogin',
            type: 'Post', //GET
            async: true,    //或false,是否异步
            data: "username=" + self.username() + "&password=" + self.password() + "&identity.identityId=" + self.selectedIdentity(),
            timeout: 5000,    //超时时间
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text

            success: function (data, textStatus, jqXHR) {
                if(data){
                    console.log("++++++++++++++++++++"+data);
                    console.log(root);
                    root.moduleOptions("welcome");
                    return;
                }else{
                    console.log("--------------------"+data);
                    root.moduleOptions("login");
                    return;
                }
            },
            error: function (data, textStatus, jqXHR) {
                console.log("登录请求失败");
            }
        })
    };

    var initSelectList = function(self){

        $.ajax({
            url: '/showSelect',
            type: 'Get', //GET
            async: true,    //或false,是否异步
            data: "",
            timeout: 5000,    //超时时间
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text

            success: function (data, textStatus, jqXHR) {
                self.identityList(data);
            }
        })

    };



    return {
        selectChange: selectChange,
        submitLoginInfo: submitLoginInfo,
        initSelectList: initSelectList
    }
});